import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:interview/config/app.enum.dart';
import 'package:interview/controller/navigation_controller.dart';
import 'package:interview/pages/account/components/input_item.dart';
import 'package:interview/theme/app_colors.dart';
import 'package:interview/utils/logger.dart';

class InputBox extends StatefulWidget {
  final AppColors theme;
  final String user_name;
  final String password;
  final bool is_agree;
  final void Function(String value) update_user_name;
  final void Function(String value) update_password;
  final void Function() update_is_agree;
  final void Function() onLogin;

  const InputBox({
    super.key, 
    required this.theme, 
    required this.user_name, 
    required this.password, 
    required this.is_agree, 
    required this.update_user_name, 
    required this.update_password, 
    required this.update_is_agree, 
    required this.onLogin, 
  });

  @override
  State<InputBox> createState() => _InputBoxState();
}

class _InputBoxState extends State<InputBox> {

  @override
  Widget build(BuildContext context) {
    final navigation = Get.find<NavigationController>();
    return Container(
      width: double.infinity,
      child: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 32),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          children: [
            Image.asset("${AppEnumAssets.basePath}icon.png", width: 128, height: 128),
            SizedBox(height: 12),
            Text("面试通", style: TextStyle( fontSize: 28,fontWeight: FontWeight.bold, color: widget.theme.contrastMix3)),
            SizedBox(height: 16 ),
            Text("搞定企业面试真题，就用面试通~", style: TextStyle( fontSize: 14,fontWeight: FontWeight.w500,color: widget.theme.contrastMix1)),
            SizedBox(height: 32),
            InputItem(
              theme:widget.theme,
              labelText: '用户名',
              placeholder: '请输入用户名',
              hintText: '请输入用户名',
              statusText:widget.user_name,
              contentPadding: EdgeInsets.only(bottom: 8),
              border: UnderlineInputBorder(
                borderSide: BorderSide(color: widget.theme.contrastMix3!, width: 0.5),
              ),
              onChanged: (value) {
                widget.update_user_name(value);
              },
              onSubmitted: (value) {
                Logger.info('Username onSubmitted: $value',tag: "用户名 onSubmitted");
              },
            ),
            SizedBox(height: 24),
            InputItem(
              theme:widget.theme,
              labelText: '密码',
              placeholder: '请输入用户名',
              contentPadding: EdgeInsets.only(bottom: 8),
              hintText: '请输入密码',
              obscureText: true,
              border: UnderlineInputBorder(
                borderSide: BorderSide(color: widget.theme.contrastMix3!, width: 0.5),
              ),
              statusText:widget.password,
              onChanged: (value) {
                widget.update_password(value);
              },
              onSubmitted: (value) {
                Logger.info('Password onSubmitted: $value',tag: "密码 onSubmitted");
              },
            ),
            SizedBox(height: 24),
            Row(
              mainAxisAlignment: MainAxisAlignment.start,
              mainAxisSize: MainAxisSize.min,
              children: [
                Checkbox(
                  value: widget.is_agree, // 根据实际情况设置初始值
                  onChanged: (bool? newValue) {
                    widget.update_is_agree();
                  },
                  activeColor: widget.theme.contrastPure, // 使用主题色
                  checkColor:widget.theme.subjectPure, // 可选，指定选中标记的颜色
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(6), // 设置圆角大小
                  ),
                  side: BorderSide(color: widget.theme.contrastMix3!), // 设置边框颜色
                ),
                Text("已阅读并同意",style: TextStyle(fontSize: 12 , color: widget.theme.contrastMix3)),
                GestureDetector(
                  child: Text("用户协议",style: TextStyle(fontSize: 12 , fontWeight: FontWeight.bold, color: widget.theme.contrastMix3)),
                  onTap: ()=>{
                    navigation.push('/webpage', parameters: {'title': '用户协议', 'url': 'https://aicenter.luyantech.com/h5/privacy.html',})
                  },
                ),
                Text("和",style: TextStyle(fontSize: 12 , color: widget.theme.contrastMix3)),
                GestureDetector(
                  child: Text("隐私协议",style: TextStyle(fontSize: 12 , fontWeight: FontWeight.bold, color: widget.theme.contrastMix3)),
                  onTap: ()=>{
                    navigation.push('/webpage',parameters: {'title': '隐私协议', 'url': 'https://aicenter.luyantech.com/h5/service_agreement.html',})
                  },
                ),
              ],
            ),
            const SizedBox(height: 24),
            GestureDetector(
              onTap: ()=> widget.onLogin(),
              child: Container(
              width: double.infinity,
              padding: const EdgeInsets.symmetric(vertical: 12),
              decoration: BoxDecoration(
                color: const Color(0xfffb7a1f),
                borderRadius: BorderRadius.circular(12), // 设置圆角
              ),
              child: Center(
                child: Text("立即登录",style: TextStyle(fontSize: 14 , fontWeight: FontWeight.bold,color: Colors.white),),
              ),
            ),
            )
          ],
        ),
      )
    );
  }
}
